<template>
    <view class="content">
        <input-item custom name="Contract">
            <image-uploader fileName="contractUrls" type="info" @change="handleUpload"></image-uploader>
        </input-item>
        <input-item custom name="Start Date">
            <uni-datetime-picker :clear-icon="false" class="input" type="date" v-model="start" />
        </input-item>
        <input-item custom name="End Date">
            <uni-datetime-picker :clear-icon="false" class="input" type="date" v-model="end" />
        </input-item>
        <view class="flex-center">
            <u-button type="primary" :text="$t('submit.submitButton')" @click="submit"></u-button>
        </view>
    </view>
</template>

<script>
import { formatDateTime, goBack, showAlert, showFailure, showMessage, showSuccess } from '../../../lib/helper';
import { updateOrder } from '../../../lib/service';
export default {
    data() {
        return {
            id: '',
            imageUrl: '',
            start: formatDateTime(new Date(), 'yyyy-MM-dd'),
            end: formatDateTime(new Date(), 'yyyy-MM-dd')
        };
    },
    onLoad(options) {
        this.id = options.id;
    },

    methods: {
        handleUpload(data) {
            var file = data[0];
            this.imageUrl = file ? file.url : '';
        },
        submit() {
            if (!this.imageUrl) {
                showAlert('Contract cannot be empty');
                return;
            }
            uni.showLoading();
            updateOrder(this.id, { contractUrls: this.imageUrl, payStatus: 1, status: 2, startTime: this.start + ' 00:00:00', endDate: this.end + ' 23:59:59' })
                .then((res) => {
                    uni.hideLoading();
                    showSuccess();
                    setTimeout(() => {
                        goBack();
                    }, 480);
                })
                .catch((err) => {
                    uni.hideLoading();
                });
        }
    }
};
</script>

<style></style>